

di "************************************************************************************************"
di "*************************************** LOAD DATA ********** ***********************************"
di "************************************************************************************************"

u "$saveddata/RESTAT_replication.dta", clear


noi di "Define regression sample, gets rid of firms that ever move enable phase"
gen smpl_reg=0
replace smpl_reg = 1 if (year == 2008 | year == 2013 | year == 2015) & !missing(cloud) & !missing(multiplant) & !missing(fgn_ent) &  !missing(ln_age_ent) & !missing(fibre_L1) & !missing(dist_fibre_L1) & ever_move==.
bysort ruref: egen maxsmpl_reg=sum(smpl_reg)
replace maxsmpl_reg=. if smpl_reg==0

label var smpl_reg					"Dummy = 1 for regression sample (keeping singletons)"
label var maxsmpl_reg				"Number of years firm is in regression sample (i.e. sum of smpl_reg)"


cd $output_location

di "************************************************************************************************"
di "*************************************** Table 1: Summary Stats  ***********************************"
di "************************************************************************************************"

foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware  {
	tabstat `var' if year<=2015 & maxsmpl_reg>=2 & smpl_reg==1  & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=., stats(mean sd n)  
}


foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware  {
	tabstat `var' if year<=2015 & maxsmpl_reg>=2 & smpl_reg==1  & young25_08==1  & ln_sales_ent!=. & dist_wav_ent!=.  & ln_ees_ent!=. & fgn_ent!=. & multiplant!=. & ln_age_ent!=., stats(mean sd n)  
}

foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware {
	tabstat `var' if year<=2015 & maxsmpl_reg>=2 & smpl_reg==1  & young25_08==0  & ln_sales_ent!=. & dist_wav_ent!=.  & ln_ees_ent!=. & fgn_ent!=. & multiplant!=. & ln_age_ent!=. , stats(mean sd n)  
}


di "************************************************************************************************"
di "*************************************** Table 2: instrument relevance ************************************************"
di "************************************************************************************************"

estimates drop _all
gl controls multiplant fgn_ent ln_age_ent

reghdfe cloud fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=.,  absorb(year ruref  ) cluster(ruref)
est store relevance1

reghdfe cloud fibre_L1  dist_500_fibre_L1-dist_2000_fibre_L1 $controls if  smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=.,  absorb(year ruref  ) cluster(ruref)
est store relevance2

esttab relevance* using "Table2.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf j aic,  fmt(%9.2f)) mlabels(,titles)


di "***************************************Table 3 OLS************************************************"
di "************************************************************************************************"

		
estimates drop _all
gl controls multiplant fgn_ent ln_age_ent
reghdfe ln_ees_ent $controls cloud   if year <= 2015 &  year>=2008 & ln_ees_ent!=.   & smpl_reg== 1    & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m1
reghdfe ln_sales_ent $controls cloud   if year <= 2015  & year>=2008 &  ln_ees_ent!=.   & smpl_reg== 1 & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m2
reghdfe ln_sales_worker $controls cloud   if year <= 2015  & year>=2008 &  ln_ees_ent!=.  & smpl_reg== 1  & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m3
reghdfe ln_ees_ent $controls cloud_inc25  cloud_yng25  if year <= 2015 & year>=2008 &  ln_ees_ent!=.   & smpl_reg== 1 & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m4
reghdfe ln_sales_ent $controls cloud_inc25  cloud_yng25  if year <= 2015  & year>=2008 &  ln_ees_ent!=.  & smpl_reg== 1  & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m5
reghdfe ln_sales_worker $controls cloud_inc25  cloud_yng25  if year <= 2015  & year>=2008 &  ln_ees_ent!=.   & smpl_reg== 1 & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m6
esttab m* using "Table3.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)


di "***************************************Table 4 regs 1-3: Baseline IVs with Age <10************************"

estimates drop _all
gl controls multiplant fgn_ent ln_age_ent
reghdfe ln_ees_ent $controls (cloud = fibre_L1 dist_fibre_L1 )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
 estimates store m1, 
		estimates restore reghdfe_first1
		estimates store m2, 
		
reghdfe ln_sales_ent $controls (cloud = fibre_L1 dist_fibre_L1 )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
qui estimates store m3, 
		estimates restore reghdfe_first1
		qui estimates store m4, 

reghdfe ln_sales_worker $controls (cloud = fibre_L1 dist_fibre_L1 )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
qui estimates store m5, 
		estimates restore reghdfe_first1
		qui estimates store m6, 

esttab m* using "Table4_r13.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)


di "***************************************Table 4 regs 4-6: Baseline IVs with Age <10************************"
di "***************************************Young <10 vs incumbent two treatments*********************"


gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker 
foreach treatment in cloud_inc25 {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'*****************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
						
			estimates drop _all
		
			
		reghdfe `outcome' $controls (`treatment' treat_interact = fibre_L1_inc25 fibre_interact dist_fibre_L1_inc25 dist_fibre_interact )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1  & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		estimates store m45, title(IV2ND+C-1315B)
					
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
				
		esttab m* using "Table4_`outcome'.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}


di "************************************************************************************************"
di "***************************************Table 5 regressions 1-3: Initial Age as a continuous variable************************************************"
di "************************************************************************************************"



gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker  
foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			estimates drop _all
		
		reghdfe `outcome' $controls (cloud treat_age = fibre_L1 fibre_age dist_fibre_L1 dist_fibre_age) if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg==1     & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref  ) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf j aic,  fmt(%9.2f)) mlabels(,titles)
					
		esttab m* using "Table5_`outcome'_regs1t3.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
}

		

di "************************************************************************************************"
di "***************************************Table 5 regressions 4-6************************************************"
di "************************************************************************************************"


gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker  
foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

		estimates drop _all
					
		reghdfe `outcome' $controls (cloud_ageq1_08 cloud_ageq2_08 cloud_ageq3_08 cloud_ageq4_08  = fibre_L1_ageq1_08 fibre_L1_ageq2_08 fibre_L1_ageq3_08 fibre_L1_ageq4_08 dist_fibre_L1_ageq1_08 dist_fibre_L1_ageq2_08 dist_fibre_L1_ageq3_08 dist_fibre_L1_ageq4_08 ) if year <= 2015 & year>=2008 & ln_ees_ent!=.  & smpl_reg== 1     & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, 
estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		estimates restore reghdfe_first3
		estimates store m45, title(IV1ST+C-1315B)
		estimates restore reghdfe_first4
		estimates store m46, title(IV1ST+C-1315B)
				
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf j aic,  fmt(%9.2f)) mlabels(,titles)
					
		esttab m* using "Table5_`outcome'_regs4t6.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}


di "***************************************Table 6: Cloud data and storage************************"
di "************************************************************************************************"

		
gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker 

foreach treatment in cloud_hard_inc25 {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud_hard * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
						
			estimates drop _all
		
			
		reghdfe `outcome' $controls (`treatment' treat_interact = fibre_L1_inc25 fibre_interact dist_fibre_L1_inc25 dist_fibre_interact ) if year <= 2015 & year>=2008 & ln_ees_ent!=. & smpl_reg==1   &  ln_sales_ent!=.  & dist_wav_ent!=. , absorb(year ruref) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "TAble6_`outcome'.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}


		
di "***************************************Table 7: Baseline IVs with Age <10************************"
di "************************************************************************************************"



cd $output_location
gl outcomes10 multiplant dead_share born_share dist_wav_ent dist_av_ent dist_cov_lu_ent ln_numla_lu_ent 

foreach treatment in cloud_inc25 {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
						
			estimates drop _all
		
			
		reghdfe `outcome' $controls (`treatment' treat_interact = fibre_L1_inc25 fibre_interact dist_fibre_L1_inc25 dist_fibre_interact ) if ln_ees_ent!=.  & year>=2008    & year<=2015   & smpl_reg== 1   & ln_sales_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, 
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "Table7_`outcome'.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}


di "************************************************************************************************"
di "*************************************** Table A1: summary stats cloud************************************************"
di "************************************************************************************************"
			

noi di "***********Summary stats all firms" 

foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware cloud_low cloud_medium cloud_high  {
	tabstat `var' if year==2013 & maxsmpl_reg>=2 & smpl_reg==1, stats(mean sd n)  
}
foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware cloud_low cloud_medium cloud_high  {
	tabstat `var' if year==2015 & maxsmpl_reg>=2 & smpl_reg==1, stats(mean sd n)  
}


noi di "***********Summary stats young" 

foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware  cloud_low cloud_medium cloud_high   {
	tabstat `var' if year==2013 & maxsmpl_reg>=2 & smpl_reg==1 & young25_08==1, stats(mean sd n)  
}
foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware  cloud_low cloud_medium cloud_high   {
	tabstat `var' if year==2015 & maxsmpl_reg>=2 & smpl_reg==1 & young25_08==1, stats(mean sd n)  
}

noi di "***********incumbent" 
foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware  cloud_low cloud_medium cloud_high   {
	tabstat `var' if year==2013 & maxsmpl_reg>=2 & smpl_reg==1 & young25_08==0, stats(mean sd n)  
}
foreach var in cloud cloud_data  cloud_storage cloud_email cloud_software  cloud_finance cloud_crm cloud_ownsoftware  cloud_low cloud_medium cloud_high   {
	tabstat `var' if year==2015 & maxsmpl_reg>=2 & smpl_reg==1 & young25_08==0, stats(mean sd n)  
}


di "************************************************************************************************"
di "*************************************** Table A2: Summary stats other variables************************************************"
di "************************************************************************************************"


noi di "***********Summary stats all years" 

foreach var in ln_ees_ent ln_sales_ent ln_sales_worker  ///
 multiplant dead_share born_share dist_av_ent dist_cov_lu_ent fibre_L1 exchange_distance_ent numla_lu_ent ///
fgn_ent  ln_age_ent services urban_ent KIA d1_ln_emp_ent d1_ln_sales_ent  d1_ln_sales_worker   {
	
	tabstat `var' if year<=2015 & maxsmpl_reg>=2 & smpl_reg==1, stats(mean sd n)  
}

*young 
noi di "***********Summary stats all years" 

foreach var in ln_ees_ent ln_sales_ent ln_sales_worker  ///
 multiplant dead_share born_share dist_av_ent dist_cov_lu_ent fibre_L1 exchange_distance_ent numla_lu_ent ///
fgn_ent  ln_age_ent services urban_ent KIA d1_ln_emp_ent d1_ln_sales_ent  d1_ln_sales_worker   {
	
	tabstat `var' if year<=2015 & maxsmpl_reg>=2 & smpl_reg==1 & young50_08==1, stats(mean sd n)  
}

*incumbent  
noi di "***********Summary stats all years" 

foreach var in ln_ees_ent ln_sales_ent ln_sales_worker  ///
 multiplant dead_share born_share dist_av_ent dist_cov_lu_ent fibre_L1 exchange_distance_ent numla_lu_ent ///
fgn_ent  ln_age_ent services urban_ent KIA d1_ln_emp_ent d1_ln_sales_ent  d1_ln_sales_worker   {
	
	tabstat `var' if year<=2015 & maxsmpl_reg>=2 & smpl_reg==1 & incumbent50_08==1, stats(mean sd n)  
}



di "***************************************Table A3 OLS************************************************"
di "************************************************************************************************"

gl controls multiplant fgn_ent  ln_age_ent
estimates drop _all
reghdfe ln_IT_inv_emp $controls cloud   if year <= 2015 &  year>=2008 & ln_ees_ent!=.   & smpl_reg== 1    & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m1
		
reghdfe ln_IT_inv_emp $controls cloud_inc25  cloud_yng25  if year <= 2015  & year>=2008 &  ln_ees_ent!=.   & smpl_reg== 1 & ln_sales_ent!=. & dist_wav_ent!=. & ln_ees_ent!=. & young25_08!=., absorb(year ruref ) cluster(ruref) 
estimates store m2
esttab m* using "Table_A3.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
	

di "************************************************************************************************"
di "*************************************** Table A4: instrument relevance ************************************************"
di "************************************************************************************************"

	
estimates drop _all
gl controls multiplant fgn_ent ln_age_ent

reghdfe cloud_data fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance1
reghdfe cloud_storage fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance2
reghdfe cloud_email fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance3
reghdfe cloud_software fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance4
reghdfe cloud_finance fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance5
reghdfe cloud_crm fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance6
reghdfe cloud_ownsoftware fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance7
reghdfe cloud_low fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance8
reghdfe cloud_medium fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance9
reghdfe cloud_high fibre_L1  dist_fibre_L1 $controls if smpl_reg== 1,  absorb(year ruref ) cluster(ruref)
est store relevance10

esttab relevance* using "TableA4.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf j aic,  fmt(%9.2f)) mlabels(,titles)



di "************************************************************************************************"
di "*************************************** Table A5: other digital technologies ************************************************"
di "************************************************************************************************"

estimates drop _all
gl controls multiplant fgn_ent  ln_age_ent

reghdfe  ln_ees_ent $controls (pcs_ees = fibre_L1 dist_fibre_L1)  if year >= 2008    & ln_ees_ent!=.  & year <= 2015,  absorb(year ruref ) cluster(ruref)   stages(first)  		old
est store m1
estimates restore reghdfe_first1
estimates store m1A, title(IV1ST+C-1315B)
		
reghdfe   ln_ees_ent $controls (internetmob_ees = fibre_L1 dist_fibre_L1)  if year >= 2008    & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m11
estimates restore reghdfe_first1
estimates store m2A, title(IV1ST+C-1315B)
		
reghdfe  ln_ees_ent $controls (online_sales  = fibre_L1 dist_fibre_L1)  if year >= 2008     & ln_ees_ent!=.  & year <= 2015 ,  absorb(year ruref  ) cluster(ruref)   stages(first) 	 		old	
est store m2
estimates restore reghdfe_first1
estimates store m3A, title(IV1ST+C-1315B)
		
reghdfe   ln_ees_ent $controls (online_sales_pc = fibre_L1 dist_fibre_L1)  if year >= 2008     & ln_ees_ent!=.  & year <= 2015 ,  absorb(year ruref  ) cluster(ruref)   stages(first) 	 		old	
est store m3
estimates restore reghdfe_first1
estimates store m4A, title(IV1ST+C-1315B)
		
reghdfe   ln_ees_ent $controls (rfid_ident = fibre_L1 dist_fibre_L1)  if year >= 2008    & ln_ees_ent!=.  & year <= 2015 ,  absorb(year ruref  ) cluster(ruref)   stages(first)  	 		old	
est store m4
estimates restore reghdfe_first1
estimates store m5A, title(IV1ST+C-1315B)
		
reghdfe   ln_ees_ent $controls (rfid_prod = fibre_L1 dist_fibre_L1)  if year >= 2008    & ln_ees_ent!=.   & year <= 2015,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m5
estimates restore reghdfe_first1
estimates store m6A, title(IV1ST+C-1315B)

reghdfe   ln_ees_ent $controls (erp = fibre_L1 dist_fibre_L1)  if year >= 2008     & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m6
estimates restore reghdfe_first1
estimates store m7A, title(IV1ST+C-1315B)

reghdfe   ln_ees_ent $controls (crm_mkt = fibre_L1 dist_fibre_L1) if year >= 2008    & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m7
estimates restore reghdfe_first1
estimates store m8A, title(IV1ST+C-1315B)

reghdfe   ln_ees_ent $controls (crm_cust = fibre_L1 dist_fibre_L1)  if year >= 2008   & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m8
estimates restore reghdfe_first1
estimates store m9A, title(IV1ST+C-1315B)

reghdfe   ln_ees_ent $controls (ict_specialists = fibre_L1 dist_fibre_L1)  if year >= 2008    & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m9
estimates restore reghdfe_first1
estimates store m10A, title(IV1ST+C-1315B)

reghdfe   ln_ees_ent $controls (ict_training = fibre_L1 dist_fibre_L1)  if year >= 2008     & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m10
estimates restore reghdfe_first1
estimates store m11A, title(IV1ST+C-1315B)

reghdfe   ln_ees_ent $controls (scm_supp = fibre_L1 dist_fibre_L1)  if year >= 2008     & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m12
estimates restore reghdfe_first1
estimates store m12A, title(IV1ST+C-1315B)

reghdfe   ln_ees_ent $controls (scm_cust = fibre_L1 dist_fibre_L1)  if year >= 2008    & ln_ees_ent!=.  ,  absorb(year ruref  ) cluster(ruref)   stages(first)  		 		old
est store m13
estimates restore reghdfe_first1
estimates store m13A, title(IV1ST+C-1315B)

esttab m* using "TableA5.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)





di "************************************************************************************************"
di "*************************************** Table A6: first stage of Table 4 regs 1-3 **************"
di "************************************************************************************************"

estimates drop _all
gl controls multiplant fgn_ent  ln_age_ent
reghdfe ln_ees_ent $controls (cloud = fibre_L1 dist_fibre_L1 )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
 estimates store m1, 
		estimates restore reghdfe_first1
		estimates store m2, 
		
reghdfe ln_sales_ent $controls (cloud = fibre_L1 dist_fibre_L1 )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
qui estimates store m3, 
		estimates restore reghdfe_first1
		qui estimates store m4, 

reghdfe ln_sales_worker $controls (cloud = fibre_L1 dist_fibre_L1 )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1   & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
qui estimates store m5, 
		estimates restore reghdfe_first1
		qui estimates store m6, 

esttab m* using "TableA6_regs1t3.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)



di "************************************************************************************************"
di "*************************************** Table A6: first stage of Table A6 regs 4-6 **************"
di "************************************************************************************************"


cd $output_location
gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker 
foreach treatment in cloud_inc25 {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'*****************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
						
			estimates drop _all
		
			
		reghdfe `outcome' $controls (`treatment' treat_interact = fibre_L1_inc25 fibre_interact dist_fibre_L1_inc25 dist_fibre_interact )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1  & ln_sales_ent!=. & dist_wav_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		estimates store m45, title(IV2ND+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "TableA6_`outcome'_regs4t6.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}



di "************************************************************************************************"
di "*************************************** Table A7: Size Interactions ***********************************"
di "************************************************************************************************"


gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker 

foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			estimates drop _all
					
		reghdfe `outcome' $controls (cloud treat_ees_log = fibre_L1 fibre_ees_log dist_fibre_L1 dist_fibre_ees_log) if year <= 2015   & ln_ees_ent!=. & smpl_reg==1 , absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf j aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "Table_A7.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
}


di "************************************************************************************************"
di "*************************************** Table A8: SIZE&AGE ************************************************"
di "************************************************************************************************"


gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker 

foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			
			
			estimates drop _all
					
		reghdfe `outcome' $controls (cloud_SMLYNGA cloud_SMLOLDA cloud_LRGYNGA cloud_LRGOLDA  = fibre_L1_SMLYNGA fibre_L1_SMLOLDA fibre_L1_LRGYNGA fibre_L1_LRGOLDA dist_fibre_L1_SMLYNGA dist_fibre_L1_SMLOLDA dist_fibre_L1_LRGYNGA dist_fibre_L1_LRGOLDA ) if year <= 2015 & year>=2008 & ln_ees_ent!=. & smpl_reg==1, absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		estimates restore reghdfe_first3
		estimates store m45, title(IV1ST+C-1315B)
		estimates restore reghdfe_first4
		estimates store m46, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf j aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "Table A8.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}


		
di "************************************************************************************************"
di "*************************************** Table A9: Cloud high ************************************************"
di "************************************************************************************************"

gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker  

foreach treatment in cloud_high_inc25 {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud_high * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
						
			estimates drop _all
					
		reghdfe `outcome' $controls (`treatment' treat_interact = fibre_L1_inc25 fibre_interact dist_fibre_L1_inc25 dist_fibre_interact ) if year <= 2015 & year>=2008 & ln_ees_ent!=.  & smpl_reg==1  , absorb(year ruref) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "TableA9.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}


di "************************************************************************************************"
di "***************************************Table A10: do young respond more to the instruments ************************************************"
di "************************************************************************************************"

gl outcomes10 ln_ees_ent 
foreach treatment in cloud {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'*****************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
						
			estimates drop _all
		
			
		reghdfe `outcome' $controls (`treatment'  = fibre_L1 fibre_interact dist_fibre_L1 dist_fibre_interact )  if ln_ees_ent!=.  & year>=2008   & year<=2015 & smpl_reg== 1 , absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "TableA10_`outcome'.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}		



di "********************************************************************************************************************************************************"
di "*************************************** Table A11: IV Regressions: Impact of cloud on firm growth: Alternative Age Groups********************************"
di "********************************************************************************************************************************************************"


gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker 

		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}
				
			estimates drop _all
					
		reghdfe `outcome' $controls (cloud_ageq1A_08 cloud_ageq2A_08 cloud_ageq3A_08 cloud_ageq4A_08  = fibre_L1_ageq1A_08 fibre_L1_ageq2A_08 fibre_L1_ageq3A_08 fibre_L1_ageq4A_08 dist_fibre_L1_ageq1A_08 dist_fibre_L1_ageq2A_08 dist_fibre_L1_ageq3A_08 dist_fibre_L1_ageq4A_08 ) if year <= 2015 & smpl_reg==1  & ln_ees_ent!=. , absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		estimates restore reghdfe_first3
		estimates store m45, title(IV1ST+C-1315B)
		estimates restore reghdfe_first4
		estimates store m46, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf j aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "TableA11_`outcome'.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
		

		
di "************************************************************************************************"
di "***************************************Step A12: Industry heterogeneity  KIA************************************************"
di "************************************************************************************************"

gl outcomes10 ln_ees_ent ln_sales_ent ln_sales_worker 
foreach treatment in cloud_inc25 {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
			cap drop treat_interact_KIA
			gen treat_interact_KIA = treat_interact*KIA
			cap drop fibre_interact_KIA
			gen fibre_interact_KIA = fibre_interact*KIA
			cap drop dist_fibre_interact_KIA
			gen dist_fibre_interact_KIA = dist_fibre_interact*KIA
			
			estimates drop _all
					
		reghdfe `outcome' $controls (`treatment' treat_interact treat_interact_KIA= fibre_L1_inc25 fibre_interact fibre_interact_KIA dist_fibre_L1_inc25 dist_fibre_interact dist_fibre_interact_KIA) if year <= 2015 & year>=2008 & ln_ees_ent!=.  & smpl_reg==1  , absorb(year ruref ) cluster(ruref) stages(first)  old
		
		estimates store m42, title(IV2ND+C-1315B)
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		estimates store m45, title(IV2ND+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "TableA12_`outcome'.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}

		
di "***************************************Table A13: first stage of Table 7************************"
di "************************************************************************************************"

gl outcomes10 multiplant dead_share born_share  dist_wav_ent dist_av_ent dist_cov_lu_ent ln_numla_lu_ent 

foreach treatment in cloud_inc25 {	
	foreach hetero in young25_08 {
		foreach outcome in $outcomes10{

		noi di "***********************Running regressions for outcome `outcome'**********************"
		
		if "`outcome'" == "multiplant"{
			gl controls fgn_ent  ln_age_ent
		}
		else{
			gl controls multiplant fgn_ent  ln_age_ent
		}

			cap drop treat_interact
			gen treat_interact = cloud * `hetero'
			cap drop fibre_interact
			gen fibre_interact = fibre_L1 * `hetero'
			cap drop dist_fibre_interact
			gen dist_fibre_interact = dist_fibre_L1 * `hetero'
			
			estimates drop _all
					
		reghdfe `outcome' $controls (`treatment' treat_interact = fibre_L1_inc25 fibre_interact dist_fibre_L1_inc25 dist_fibre_interact ) if ln_ees_ent!=.  & year>=2008    & year<=2015   & smpl_reg== 1   & ln_sales_ent!=., absorb(year ruref ) cluster(ruref) stages(first)  old
		estimates store m42, 
		estimates restore reghdfe_first1
		estimates store m43, title(IV1ST+C-1315B)
		estimates restore reghdfe_first2
		estimates store m44, title(IV1ST+C-1315B)
		esttab m*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
		esttab m* using "TableA13_`outcome'_table7.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
			
		}
	}
}



di "************************************************************************************************"
di "***************************************APPENDIX SECTION B****************************************"
di "************************************************************************************************"



use "$MERGED_ASHE_ENTREF_19982017_ALL.dta", clear
drop if birth_ent > 2008

cap drop id
egen id = group(entref piden)

gen tenure_ashe_sq = tenure_ashe * tenure_ashe
gen skilled10 = 0 if !missing(skill10_ashe)
replace skilled10 = 1 if skill10_ashe == 3 | skill10_ashe == 4
gen unskilled10 = 0 if !missing(skill10_ashe)
replace unskilled10 = 1 if skill10_ashe == 1 | skill10_ashe == 2
foreach var of varlist age_ashe tenure_ashe tenure_ashe_sq skilled10{
	gen `var'_sex = `var' * sex_ashe
}

tsset piden year
gen temp = F2.dist_lu
gen gr_dist_lu_D2_ashe = ln(temp) - ln(dist_lu) if lu_change_D2_ashe == 1
replace gr_dist_lu_D2_ashe = 0 if lu_change_D2_ashe == 0
gen gr_dist_lu_D2_ashe_orig = ln(temp) - ln(dist_lu) 
drop temp
gen temp = F1.dist_lu
gen gr_dist_lu_D1_ashe = ln(temp) - ln(dist_lu) if lu_change_D1_ashe == 1
replace gr_dist_lu_D1_ashe = 0 if lu_change_D2_ashe == 0
gen gr_dist_lu_D1_ashe_orig = ln(temp) - ln(dist_lu) 
drop temp


gen byte bband_medfast = 0 if year >= 2010 & !missing(bband_0_2mbps) & !missing(bband_2_10mbps) 
replace bband_medfast = 1 if year >= 2010 & (bband_10_30mbps == 1| bband_30_100mbps == 1 | bband_100mbps == 1) 

gen byte bband_med = 0 if year >= 2010 & !missing(bband_0_2mbps) | !missing(bband_2_10mbps) 
replace bband_med = 1 if year >= 2010 & (bband_10_30mbps == 1| bband_30_100mbps == 1) 



*Roll back broadband
gen broadband_fxd_imp = broadband_fxd
gen broadband_adsl_imp = broadband_adsl
gen broadband_other_fxd_imp = broadband_other_fxd
replace broadband_adsl_imp= 0 if  year < 2000	


forvalues year = 2007(-1)2000{
	gen broadband_fxd_imp_`year' = broadband_fxd_imp if year == `year'
	bysort entref (broadband_fxd_imp_`year'): replace broadband_fxd_imp_`year'=broadband_fxd_imp_`year'[1] if missing(broadband_fxd_imp_`year')
	replace broadband_fxd_imp = 0 if broadband_fxd_imp_`year' == 0 & year < `year' & missing(broadband_fxd_imp)
	drop broadband_fxd_imp_`year'
	
	gen broadband_other_fxd_imp_`year' = broadband_other_fxd_imp if year == `year'
	bysort entref (broadband_other_fxd_imp_`year'): replace broadband_other_fxd_imp_`year'=broadband_other_fxd_imp_`year'[1] if missing(broadband_other_fxd_imp_`year')
	replace broadband_other_fxd_imp = 0 if broadband_other_fxd_imp_`year' == 0 & year < `year' & missing(broadband_other_fxd_imp)
	drop broadband_other_fxd_imp_`year'
	
	gen broadband_adsl_imp_`year' = broadband_adsl_imp if year == `year'
	bysort entref (broadband_adsl_imp_`year'): replace broadband_adsl_imp_`year'=broadband_adsl_imp_`year'[1] if missing(broadband_adsl_imp_`year')
	replace broadband_adsl_imp = 0 if broadband_adsl_imp_`year' == 0 & year < `year' & missing(broadband_adsl_imp)
	drop broadband_adsl_imp_`year'
}


*Impute with adsl  // is this ok?
gen bband_fast_imp = bband_fast
replace bband_fast_imp= 0 if  (broadband_other_fxd_imp == 0 | broadband_adsl_imp == 1) & year <= 2009	

gen bband_medfast_imp = bband_medfast
replace bband_medfast_imp= 0 if  (broadband_other_fxd_imp == 0 | broadband_adsl_imp == 1) & year <= 2009	


gen bband_med_imp = bband_med
replace bband_med_imp= 0 if  (broadband_other_fxd_imp == 0 | broadband_adsl_imp == 1) & year <= 2009	

gen bband_100mbps_imp = bband_100mbps
replace bband_100mbps_imp= 0 if  (broadband_other_fxd_imp == 0 | broadband_adsl_imp == 1) & year <= 2009	

gen bband_10_30mbps_imp = bband_10_30mbps
replace bband_10_30mbps_imp= 0 if  (broadband_other_fxd_imp == 0 | broadband_adsl_imp == 1) & year <= 2009	

gen bband_30_100mbps_imp = bband_30_100mbps
replace bband_30_100mbps_imp= 0 if  (broadband_other_fxd_imp == 0 | broadband_adsl_imp == 1) & year <= 2009	


*Non-leasedline imputation
gen bband_medfast_imp1 = bband_medfast
replace bband_medfast_imp1= 0 if  (broadband_other_fxd_imp == 0) & year <= 2009	

gen bband_fast_imp1 = bband_fast
replace bband_fast_imp1= 0 if  (broadband_other_fxd_imp == 0) & year <= 2009	

gen bband_med_imp1 = bband_med
replace bband_med_imp1= 0 if  (broadband_other_fxd_imp == 0) & year <= 2009	

gen bband_100mbps_imp1 = bband_100mbps
replace bband_100mbps_imp1= 0 if  (broadband_other_fxd_imp == 0) & year <= 2009	


*Roll back non-adoption
forvalues year=2016(-1)2008{
	gen bband_fast_imp_`year' = bband_fast_imp if year == `year'
	bysort entref (bband_fast_imp_`year'): replace bband_fast_imp_`year'=bband_fast_imp_`year'[1] if missing(bband_fast_imp_`year')
	replace bband_fast_imp = 0 if bband_fast_imp_`year' == 0 & year < `year' & missing(bband_fast_imp)
	drop bband_fast_imp_`year'
	
	gen bband_medfast_imp_`year' = bband_medfast_imp if year == `year'
	bysort entref (bband_medfast_imp_`year'): replace bband_medfast_imp_`year'=bband_medfast_imp_`year'[1] if missing(bband_medfast_imp_`year')
	replace bband_medfast_imp = 0 if bband_medfast_imp_`year' == 0 & year < `year' & missing(bband_medfast_imp)
	drop bband_medfast_imp_`year'
	
	gen bband_medfast_imp1_`year' = bband_medfast_imp1 if year == `year'
	bysort entref (bband_medfast_imp1_`year'): replace bband_medfast_imp1_`year'=bband_medfast_imp1_`year'[1] if missing(bband_medfast_imp1_`year')
	replace bband_medfast_imp1 = 0 if bband_medfast_imp1_`year' == 0 & year < `year' & missing(bband_medfast_imp1)
	drop bband_medfast_imp1_`year'
	/*
	gen bband_med_imp_`year' = bband_med_imp if year == `year'
	bysort entref (bband_med_imp_`year'): replace bband_med_imp_`year'=bband_med_imp_`year'[1] if missing(bband_med_imp_`year')
	replace bband_med_imp = 0 if bband_med_imp_`year' == 0 & year < `year'
	drop bband_med_imp_`year'
	
	gen bband_med_imp1_`year' = bband_med_imp1 if year == `year'
	bysort entref (bband_med_imp1_`year'): replace bband_med_imp1_`year'=bband_med_imp1_`year'[1] if missing(bband_med_imp1_`year')
	replace bband_med_imp1 = 0 if bband_med_imp1_`year' == 0 & year < `year'
	drop bband_med_imp1_`year'
	*/
	gen bband_100mbps_imp1_`year' = bband_100mbps_imp1 if year == `year'
	bysort entref (bband_100mbps_imp1_`year'): replace bband_100mbps_imp1_`year'=bband_100mbps_imp1_`year'[1] if missing(bband_100mbps_imp1_`year')
	replace bband_100mbps_imp1 = 0 if bband_100mbps_imp1_`year' == 0 & year < `year' & missing(bband_100mbps_imp1)
	drop bband_100mbps_imp1_`year'
	
	gen bband_100mbps_imp_`year' = bband_100mbps_imp if year == `year'
	bysort entref (bband_100mbps_imp_`year'): replace bband_100mbps_imp_`year'=bband_100mbps_imp_`year'[1] if missing(bband_100mbps_imp_`year')
	replace bband_100mbps_imp = 0 if bband_100mbps_imp_`year' == 0 & year < `year' & missing(bband_100mbps_imp)
	drop bband_100mbps_imp_`year'
	
		gen bband_10_30mbps_imp_`year' = bband_10_30mbps_imp if year == `year'
	bysort entref (bband_10_30mbps_imp_`year'): replace bband_10_30mbps_imp_`year'=bband_10_30mbps_imp_`year'[1] if missing(bband_10_30mbps_imp_`year')
	replace bband_10_30mbps_imp = 0 if bband_10_30mbps_imp_`year' == 0 & year < `year' & missing(bband_10_30mbps_imp)
	drop bband_10_30mbps_imp_`year'
	
		gen bband_30_100mbps_imp_`year' = bband_30_100mbps_imp if year == `year'
	bysort entref (bband_30_100mbps_imp_`year'): replace bband_30_100mbps_imp_`year'=bband_30_100mbps_imp_`year'[1] if missing(bband_30_100mbps_imp_`year')
	replace bband_30_100mbps_imp = 0 if bband_30_100mbps_imp_`year' == 0 & year < `year' & missing(bband_30_100mbps_imp)
	drop bband_30_100mbps_imp_`year'
	
	/*
	gen bband_med_imp1_`year' = bband_med_imp1 if year == `year'
	bysort entref (bband_med_imp1_`year'): replace bband_med_imp1_`year'=bband_med_imp1_`year'[1] if missing(bband_med_imp1_`year')
	replace bband_med_imp1 = 0 if bband_med_imp1_`year' == 0 & year < `year'
	drop bband_med_imp1_`year'
	*/
	
}

replace bband_med_imp = bband_medfast_imp - bband_100mbps_imp
replace bband_med_imp1 = bband_medfast_imp1 - bband_100mbps_imp1


cap drop restrict_firm_reg smpl_firm_reg smpl_firm_reg_panel smpl_worker_firm_reg_panel
gen restrict_firm_reg = 1 if (!(missing(bband_fast_imp)&missing(bband_medfast_imp)&missing(bband_med_imp)) | !missing(cloud) | !(missing(broadband_adsl)&missing(broadband_fxd))) & !missing(fibre_L1) & !missing(dist_fibre_L1)  & !missing(multiplant) & !missing(fgn_ent) & !missing(age_ent)  & year >= 2007 & year <= 2016 & birth_ent <= 2008 & !missing(fibre_enable_year_ent)
gen restrict_speed_firm_reg = 1 if restrict_firm_reg== 1 & !(missing(bband_fast_imp)&missing(bband_medfast_imp)&missing(bband_med_imp))
gen restrict_cloud_firm_reg = 1 if restrict_firm_reg== 1 & !(missing(lu_change_D1_ashe))
bysort entref year (restrict_cloud_firm_reg): gen smpl_cloud_firm_reg = 1 if _n == 1
replace smpl_cloud_firm_reg  = . if restrict_cloud_firm_reg!= 1


bysort entref year (restrict_firm_reg): gen smpl_firm_reg = 1 if _n == 1
replace smpl_firm_reg  = . if restrict_firm_reg!= 1
bysort entref: gen smpl_firm_reg_panel =sum(smpl_firm_reg)
bysort entref: gen smpl_worker_firm_reg_panel =sum(restrict_firm_reg)
bysort entref: gen smpl_worker_cloud_firm_reg_panel =sum(restrict_cloud_firm_reg)
bysort entref (restrict_firm_reg): gen first_firm = 1 if _n == 1
replace first_firm  = . if restrict_firm_reg!= 1
bysort entref year (restrict_firm_reg): gen num_workers = _N
replace num_workers = . if restrict_firm_reg != 1

*check stats
tabstat cloud bband_med_imp1 bband_medfast_imp bband_medfast_imp1 if smpl_firm_reg== 1 & smpl_firm_reg_panel >=2, by(year) stats(n)

*gen ees_ent_08 = ees_ent if year == 2008
*bysort entref (ees_ent_08): replace ees_ent_08 = ees_ent_08[1] if missing(ees_ent_08)

//Define skill dummies
gen skilled = 0 if !missing(skill10_ashe)
replace skilled = 1 if skill10_ashe == 3 | skill10_ashe == 4
gen unskilled = 0 if !missing(skill10_ashe)
replace unskilled = 1 if skill10_ashe == 1 | skill10_ashe == 2

gen lowskill = 0 if !missing(skill10_ashe)
replace lowskill = 1 if skill10_ashe == 1
gen medlowskill = 0 if !missing(skill10_ashe)
replace medlowskill = 1 if skill10_ashe == 2
gen medhighskill = 0 if !missing(skill10_ashe)
replace medhighskill = 1 if skill10_ashe == 3
gen highskill = 0 if !missing(skill10_ashe)
replace highskill = 1 if skill10_ashe == 4

foreach var of varlist skilled unskilled lowskill medlowskill medhighskill highskill{
	gen temp = `var' if year == 2008
	bysort piden (temp): replace temp=temp[1] if !missing(unskilled)
	replace `var' = temp
	drop temp
}


sum ees_ent if restrict_speed_firm_reg == 1 & smpl_firm_reg == 1, detail		// 
*egen ees_ent_p95 = pctile(ees_ent) if restrict_speed_firm_reg == 1 & smpl_firm_reg == 1, p(95)
egen ees_ent_p95 = pctile(ees_ent) if restrict_cloud_firm_reg == 1 & smpl_cloud_firm_reg == 1, p(95)
bysort year (ees_ent_p95): replace ees_ent_p95 = ees_ent_p95[1] if missing(ees_ent_p95)
gen temp = 1 
bysort temp (ees_ent_p95): replace ees_ent_p95 = ees_ent_p95[1] if missing(ees_ent_p95)
drop temp

cap drop ees_ent_08_pw50 fibre_sizew fibre_L1_sizew			//
egen ees_ent_08_pw50 = mean(ees_ent_08) if restrict_cloud_firm_reg == 1 & smpl_worker_firm_reg_panel >= 2 & ees_ent<ees_ent_p95
bysort year (ees_ent_08_pw50): replace ees_ent_08_pw50 = ees_ent_08_pw50[1] if missing(ees_ent_08_pw50)
gen fibre_sizew = fibre * (ln(ees_ent_08) - ln(ees_ent_08_pw50))
gen fibre_L1_sizew = fibre_L1 * (ln(ees_ent_08) - ln(ees_ent_08_pw50))


foreach var of varlist bband_med_imp1 bband_medfast_imp bband_medfast_imp1 cloud fibre fibre_sizew fibre_L1 fibre_L1_sizew{
	cap drop `var'_skill `var'_unskill `var'_lskill `var'_mlskill `var'_mhskill `var'_hskill
	gen `var'_skill = `var' * skilled
	gen `var'_unskill = `var' * unskilled
	
	gen `var'_lskill = `var' * lowskill
	gen `var'_mlskill = `var' * medlowskill
	gen `var'_mhskill = `var' * medhighskill
	gen `var'_hskill = `var' * highskill
}

bysort entref year: gen first_adsl = 1 if _n == 1

gen adsl = 0 if !missing(adsl_enable_year_ent)
replace adsl = 1 if year >=adsl_enable_year_ent & !missing(adsl_enable_year_ent)
gen dist_adsl = adsl * exchange_distance_lu
gen adsl_L1 = 0 if !missing(adsl_enable_year_ent)
replace adsl_L1 = 1 if year > adsl_enable_year_ent & !missing(adsl_enable_year_ent)
gen dist_adsl_L1 = adsl * exchange_distance_lu

gen restrict_afirm_reg = 1 if !missing(broadband_adsl_imp) & !missing(adsl_L1) & !missing(multiplant) & !missing(fgn_ent) & !missing(age_ent)  & year >= 1999 & year <= 2002 & birth_ent <= 1999 & adsl_enable_year_ent <= 2002
bysort entref: gen smpl_worker_afirm_reg_panel =sum(restrict_afirm_reg)

*gen ees_ent_00 = ees_ent if year == 2000
*bysort entref (ees_ent_00): replace ees_ent_00 = ees_ent_00[1] if missing(ees_ent_00)
egen ees_ent_99_pw50 = mean(ees_ent_99) if restrict_afirm_reg == 1 & smpl_worker_afirm_reg_panel >= 2 & ees_ent<ees_ent_p95
gen temp = 1
bysort temp (ees_ent_99_pw50): replace ees_ent_99_pw50 = ees_ent_99_pw50[1] if missing(ees_ent_99_pw50)
drop temp

gen adsl_sizew = adsl * (ln(ees_ent_99) - ln(ees_ent_99_pw50))
gen adsl_L1_sizew = adsl_L1 * (ln(ees_ent_99) - ln(ees_ent_99_pw50))

gen padsl_L1 = 0 if !missing(adsl_enable_year_lu)
replace padsl_L1 = 1 if year >adsl_enable_year_lu & !missing(adsl_enable_year_lu)
gen padsl = 0 if !missing(adsl_enable_year_lu)
replace padsl = 1 if year >=adsl_enable_year_lu & !missing(adsl_enable_year_lu)
gen pbroadband_fxd = broadband_fxd * padsl
gen pbroadband_fxd_imp = broadband_fxd_imp * padsl
gen padsl_adsl = adsl * padsl
gen padsl_adsl_L1 = adsl_L1 * padsl

foreach var of varlist broadband_fxd_imp pbroadband_fxd_imp broadband_adsl_imp adsl_L1 padsl_adsl_L1{
	cap drop `var'_skill `var'_unskill `var'_lskill `var'_mlskill `var'_mhskill `var'_hskill
	gen `var'_skill = `var' * skilled
	gen `var'_unskill = `var' * unskilled
	
	gen `var'_lskill = `var' * lowskill
	gen `var'_mlskill = `var' * medlowskill
	gen `var'_mhskill = `var' * medhighskill
	gen `var'_hskill = `var' * highskill
}

*firms with workers in at least 1 skill category
cap drop skill10_ws_pos
bysort entref year skill10_ashe: gen skill10_ws_num = sum(restrict_firm_reg) 
replace skill10_ws_num = . if (skill10_ws_num > 1 & !missing(skill10_ws_num)) | missing(skill10_ashe)
bysort entref year: egen skill10_ws_pos = sum(skill10_ws_num) 
drop skill10_ws_num

cap drop skill00_ws_pos
bysort entref year skill00_ashe: gen skill00_ws_num = sum(restrict_afirm_reg) 
replace skill00_ws_num = . if (skill00_ws_num > 1 & !missing(skill00_ws_num)) | missing(skill00_ashe)
bysort entref year: egen skill00_ws_pos = sum(skill00_ws_num) 
drop skill00_ws_num

*Define plant cloud & fibre variables
gen pfibre = 0 if !missing(fibre_enable_year_lu)
replace pfibre = 1 if year >= fibre_enable_year_lu
gen pfibre_L1 = 0 if !missing(fibre_enable_year_lu)
replace pfibre_L1 = 1 if year > fibre_enable_year_lu
gen pcloud =  cloud * pfibre
gen pfibre_fibre_L1 = pfibre_L1 * fibre_L1
gen pfibre_fibre_L1_sizew = pfibre_L1 * fibre_L1_sizew

*Define changes in distances from HQ (for workers)
tsset piden year
gen gr1_dist_lu = ln(F1.dist_lu+0.001) - ln(dist_lu+0.001)
replace gr1_dist_lu = 0 if lu_change_D1_ashe == 0
gen gr2_dist_lu = ln(F2.dist_lu+0.001) - ln(dist_lu+0.001)
replace gr2_dist_lu = 0 if lu_change_D2_ashe == 0

*Manager interaction using 2010 occupation code definition
gen man10 = 0 if manager10_ashe <= 2
replace man10 = 1 if manager10_ashe > 2 & !missing(manager10_ashe)
gen pcloud_man10 =  cloud * pfibre * man10
gen pfibre_fibre_L1_man10 = pfibre_L1 * fibre_L1 * man10
gen pfibre_fibre_L1_sizew_man10 = pfibre_L1 * fibre_L1_sizew * man10

*Manager interaction using ashe question definition
gen pcloud_man =  cloud * pfibre * manager_ashe
gen pfibre_fibre_L1_man = pfibre_L1 * fibre_L1 * manager_ashe
gen pfibre_fibre_L1_sizew_man = pfibre_L1 * fibre_L1_sizew * manager_ashe


* Summary statistics

foreach var in mult_jobs_ashe sex_ashe pt_ashe ft_ashe bpay_ashe gpay_ashe ovpay_ashe sppay_ashe bhr_ashe thrs_ashe ovhrs_ashe {
	di "Summary statistics for var `var'"
	tabstat `var', stats(n mean) by(year)
}

foreach var in manager_ashe manager10_ashe manager_new_ashe  skill00_ashe skill10_ashe{
	di "Summary statistics for var `var'"
	tabulate year `var', row nofreq
	table year `var'
}




di "************************************************************************************************"
di "***************************************Plant Switching*************************************************"
di "************************************************************************************************"

estimates drop _all
reghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates store s1
reghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates restore reghdfe_first1
estimates store f1
reghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates restore reghdfe_first2
estimates store pf1

estimates drop _all
reghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates store s2
reghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates restore reghdfe_first1
estimates store f2
reghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates restore reghdfe_first2
estimates store pf2


reghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates store s3
reghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates restore reghdfe_first1
estimates store f3
reghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates restore reghdfe_first2
estimates store pf3

reghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates store s4
reghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates restore reghdfe_first1
estimates store f4
reghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates restore reghdfe_first2
estimates store pf4


reghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates store s5
reghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates restore reghdfe_first1
estimates store f5
reghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref) stages(first)
estimates restore reghdfe_first2
estimates store pf5

reghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates store s6
reghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates restore reghdfe_first1
estimates store f6
reghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref) stages(first)
estimates restore reghdfe_first2
estimates store pf6

esttab s* using "TableB2_Second_Stage.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
esttab f* using "TableB2_First_Stage_Cloud.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
esttab pf* using "TableB2_First_Stage_PlantCloud.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)



